package edu.cuit.avatar.method;

/**
 * 打印前n个素数
 */
public class PrimeNumber {
    /**
     * 打印前primes个素数,每行打印10个
     * @param primes 素数个数
     */
    public static void printPrimeNumber(int primes){
        final int NUMBER_OF_LINES = 10;
        int count = 0;
        int number = 2;
        while(count < primes){
            if(isPrime(number)){
                count++;
                System.out.printf("%4d%s",number, count % NUMBER_OF_LINES == 0 ? "\r\n" : "  ");
            }
            number++;
        }
    }

    /**
     * 判断整数number是否为一个素数
     * @param number 整数number
     * @return 素数:true
     */
    public static boolean isPrime(int number){
        for(int divisor = 2; divisor <= number / 2; divisor++){
            if(number % divisor == 0)
                return false;
        }
        return true;
    }


    public static void main(String[] args) {
        printPrimeNumber(50);
    }
}
